home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / BSP Tree 1.2 / Sources / Graphics / source / tuple_3d.cp < prev    next >
Encoding:
Text File  |  1995-03-25  |  6.1 KB  |  105 lines  |  [TEXT/MMCC]

  1. //------------------------------------------------------------------------------
  2. //    File:                    tuple_3d.cp
  3. //    Date:                    8/26/94
  4. //    Author:                Bretton Wade
  5. //
  6. //    Description:    this file contains the methods for a tuple_3d
  7. //
  8. //------------------------------------------------------------------------------
  9.  
  10. #include "utility.h"
  11. #include "tuple_3d.h"
  12.  
  13. //------------------------------------------------------------------------------
  14. //    constructor
  15. //------------------------------------------------------------------------------
  16. tuple_3d::tuple_3d (const tuple_3d &t)                                                                                    //    copy constructor
  17. {                                                                                                                                                                //    begin
  18.     xyz[X] = t[X]; xyz[Y] = t[Y]; xyz[Z] = t[Z]; xyz[W] = t[W];                                        //    copy the values into the tuple_3d
  19. }                                                                                                                                                                //    end
  20.  
  21. //------------------------------------------------------------------------------
  22. //    constructor
  23. //------------------------------------------------------------------------------
  24. tuple_3d::tuple_3d (real x, real y, real z, real w)                                                            //    constructor from 4 values
  25. {                                                                                                                                                                //    begin
  26.     xyz[X] = x; xyz[Y] = y; xyz[Z] = z; xyz[W] = w;                                                                //    copy the values into the tuple_3d
  27. }                                                                                                                                                                //    end
  28.  
  29. //------------------------------------------------------------------------------
  30. //    assignment operator
  31. //------------------------------------------------------------------------------
  32. void    tuple_3d::operator = (const tuple_3d &t)                                                                    //    assignment operator
  33. {                                                                                                                                                                //    begin
  34.     xyz[X] = t[X]; xyz[Y] = t[Y]; xyz[Z] = t[Z]; xyz[W] = t[W];                                        //    copy the values into the tuple_3d
  35. }                                                                                                                                                                //    end
  36.  
  37. //------------------------------------------------------------------------------
  38. //    equality test
  39. //------------------------------------------------------------------------------
  40. bool    tuple_3d::operator == (const tuple_3d &t) const                                                        //    equality operator
  41. {                                                                                                                                                                //    begin
  42.     return    bool ((abs (xyz[X] - t[X]) < EPSILON) &&                                                             //    compare the x coordinates
  43.                                 (abs (xyz[Y] - t[Y]) < EPSILON) &&                                                            //    compare the y coordinates
  44.                                 (abs (xyz[Z] - t[Z]) < EPSILON) &&                                                             //    compare the z coordinates
  45.                                 (abs (xyz[W] - t[W]) < EPSILON));                                                                //    compare the w coordinates            
  46. }                                                                                                                                                                //    end
  47.  
  48. //------------------------------------------------------------------------------
  49. //    inequality test
  50. //------------------------------------------------------------------------------
  51. bool    tuple_3d::operator != (const tuple_3d &t) const                                                        //    inequality operator
  52. {                                                                                                                                                                //    begin
  53.     return    bool ((abs (xyz[X] - t[X]) > EPSILON) ||                                                             //    compare the x coordinates
  54.                                 (abs (xyz[Y] - t[Y]) > EPSILON) ||                                                            //    compare the y coordinates
  55.                                 (abs (xyz[Z] - t[Z]) > EPSILON) ||                                                             //    compare the z coordinates
  56.                                 (abs (xyz[W] - t[W]) > EPSILON));                                                                //    compare the w coordinates            
  57. }                                                                                                                                                                //    end
  58.  
  59. //------------------------------------------------------------------------------
  60. //    assignment
  61. //------------------------------------------------------------------------------
  62. void    tuple_3d::operator () (real x, real y, real z, real w)                                        //    function call operator
  63. {                                                                                                                                                                //    begin
  64.     xyz[X] = x; xyz[Y] = y; xyz[Z] = z; xyz[W] = w;                                                                //    copy the values into the tuple_3d
  65. }                                                                                                                                                                //    end
  66.  
  67. //------------------------------------------------------------------------------
  68. //    dot product
  69. //------------------------------------------------------------------------------
  70. real    tuple_3d::operator | (const tuple_3d &t) const                                                        //    inner product operator
  71. {                                                                                                                                                                //    begin
  72.     return     (xyz[X] * t[X]) +                                                                                                         //    return a scalar, x coordinate multiply
  73.                     (xyz[Y] * t[Y]) +                                                                                                            //    y coordinate multiply
  74.                     (xyz[Z] * t[Z]) +                                                                                                            //    z coordinate multiply
  75.                     (xyz[W] * t[W]);                                                                                                            //    w coordinate multiply
  76. }                                                                                                                                                                //    end
  77.  
  78. //------------------------------------------------------------------------------
  79. //    compute the major axis
  80. //------------------------------------------------------------------------------
  81. coord    tuple_3d::MajorAxis (void) const                                                                                    //    return the major axis of the tuple_3d
  82. {                                                                                                                                                                //    begin
  83.     coord    axis = X;                                                                                                                                //    the major axis of the tuple_3d, start with x
  84.     if (abs (xyz[Y]) > abs (xyz[X]))                                                                                            //    if the y component of the tuple_3d is greater than x
  85.         axis = Y;                                                                                                                                        //    y is the major axis
  86.     if (abs (xyz[Z]) > abs (xyz[axis]))                                                                                        //    if the Z component of the tuple_3d is greater
  87.         axis = Z;                                                                                                                                        //    z is the major axis
  88.     return axis;                                                                                                                                    //    return the axis
  89. }                                                                                                                                                                //    end
  90.  
  91. //------------------------------------------------------------------------------
  92. //    compute the minor axis
  93. //------------------------------------------------------------------------------
  94. coord    tuple_3d::MinorAxis (void) const                                                                                    //    return the minor axis of the tuple_3d
  95. {                                                                                                                                                                //    begin
  96.     coord    axis = X;                                                                                                                                //    the major axis of the tuple_3d, start with x
  97.     if (abs (xyz[Y]) <= abs (xyz[X]))                                                                                            //    if the y component of the tuple_3d is greater than x
  98.         axis = Y;                                                                                                                                        //    y is the major axis
  99.     if (abs (xyz[Z]) <= abs (xyz[axis]))                                                                                    //    if the Z component of the tuple_3d is greater
  100.         axis = Z;                                                                                                                                        //    z is the major axis
  101.     return axis;                                                                                                                                    //    return the axis
  102. }                                                                                                                                                                //    end
  103.  
  104. //------------------------------------------------------------------------------
  105.